<template>
  <el-container class="main_con"  style="padding-bottom:0px">
   <ufrom @submit="saveData" ref="ufrom">

        <el-form size="medium" label-width="100px" ref="itemForm" :model="obj.configuration" :rules="itemRules">

          <div class="setting_body_item">
            <div class="header">优惠券统一说明</div>
            <div class="conetnt edit_con">
              <div class="edit_content">
                <el-form-item label="使用说明" prop="explain">
                  <tinymce v-model="obj.configuration.explain" :height="300" />
                </el-form-item>
              </div>
            </div>
          </div>

        </el-form>
   </ufrom>
  </el-container>
</template>

<script>
import Tinymce from '@/components/Tinymce';
import {
  addSiteConfig,
  editSiteConfig,
  getSiteConfig
} from '@/api/shop/setting';
export default {
  data(){
    return {
      isLoading:false,
      obj:{
        type:'couponExplain',
        status:1,
        configuration:{
          explain:''
        }
      },
      itemRules:{
        explain: [{
          required: true,
          message: '内容不能为空',
        }]
      }
    }
  },
  components: {
    Tinymce
  },
  mounted(){
    this.getConfig('couponExplain');
  },
  methods: {
    //获取站点配置数据
    getConfig(type){
      this.isLoading = true;
      getSiteConfig(type).then(res => {
        this.isLoading = false;
        if(res.msg){
          this.obj = res.msg;
        };
      }).catch(e => {
        this.isLoading = false;
      })
    },
    //保存数据
    saveData(){
      this.$refs.itemForm.validate(valid => {
        if(valid){

          if(this.obj.update_time){
            //更新
            editSiteConfig(this.obj).then(res => {
              this.$refs.ufrom.init();
              this.getConfig('couponExplain');
            }).catch(e => {
              this.$refs.ufrom.init();
            });
          }else{
            //新增
            addSiteConfig(this.obj).then(res => {
              this.$refs.ufrom.init();
              this.getConfig('couponExplain');
            }).catch(e => {
              this.$refs.ufrom.init();
            });
          };

        }else{
          this.$refs.ufrom.init();
          //校验没通过
          return false;
        }
      });
    }
  }
}
</script>
